<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    有了这款可视化工具JVisualVM ，Java 应用性能调优.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-tips/有了这款可视化工具JVisualVM ，Java 应用性能调优"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  有了这款可视化工具JVisualVM ，Java 应用性能调优.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/tips/%E6%9C%89%E4%BA%86%E8%BF%99%E6%AC%BE%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B7%A5%E5%85%B7JVisualVM%20%EF%BC%8CJava%20%E5%BA%94%E7%94%A8%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/tips/">tips</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.6k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="有了这款可视化工具JVisualVM-，Java-应用性能调优"><a href="#有了这款可视化工具JVisualVM-，Java-应用性能调优" class="headerlink" title="有了这款可视化工具JVisualVM ，Java 应用性能调优"></a>有了这款可视化工具JVisualVM ，Java 应用性能调优</h1><ul>
<li>JVisualVM 简介</li>
<li>案例分析</li>
<li>准备模拟内存泄漏样例</li>
<li>使用JVisualVM分析内存泄漏</li>
<li>JVisualVM 远程监控 Tomcat</li>
</ul>
<h1 id="JVisualVM-简介"><a href="#JVisualVM-简介" class="headerlink" title="JVisualVM 简介"></a>JVisualVM 简介</h1><p>VisualVM 是Netbeans的profile子项目，已在JDK6.0 update 7 中自带，能够监控线程，内存情况，查看方法的CPU时间和内存中的对 象，已被GC的对象，反向查看分配的堆栈(如100个String对象分别由哪几个对象分配出来的)。在JDK_HOME/bin(默认是C:\Program Files\Java\jdk1.6.0_13\bin)目录下面，有一个jvisualvm.exe文件，双击打开，从UI上来看，这个软件是基于NetBeans开发的了。</p>
<p>VisualVM 提供了一个可视界面，用于查看 Java 虚拟机 (Java Virtual Machine, JVM) 上运行的基于 Java 技术的应用程序的详细信息。VisualVM 对 Java Development Kit (JDK) 工具所检索的 JVM 软件相关数据进行组织，并通过一种使您可以快速查看有关多个 Java 应用程序的数据的方式提供该信息。您可以查看本地应用程序或远程主机上运行的应用程序的相关数据。此外，还可以捕获有关 JVM 软件实例的数据，并将该数据保存到本地系统，以供后期查看或与其他用户共享。</p>
<p>双击启动 jvisualvm.exe，启动起来后和jconsole 一样同样可以选择本地和远程，如果需要监控远程同样需要配置相关参数。</p>
<p>主界面如下；</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172608491.webp" alt="img"></p>
<p>VisualVM可以根据需要安装不同的插件，每个插件的关注点都不同，有的主要监控GC，有的主要监控内存，有的监控线程等。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605298.webp" alt="img"></p>
<p>如何安装：</p>
<blockquote>
<p>1、从主菜单中选择“工具”&gt;“插件”。2、在“可用插件”标签中，选中该插件的“安装”复选框。单击“安装”。3、逐步完成插件安装程序。</p>
</blockquote>
<p>我这里以 Eclipse(pid 22296)为例，双击后直接展开，主界面展示了系统和jvm两大块内容，点击右下方jvm参数和系统属性可以参考详细的参数信息.</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605550.webp" alt="img"></p>
<p>因为VisualVM的插件太多，我这里主要介绍三个我主要使用几个：监控、线程、Visual GC</p>
<p>监控的主页其实也就是，cpu、内存、类、线程的图表</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605297.webp" alt="img"></p>
<p>线程和jconsole功能没有太大的区别</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605464.webp" alt="img"></p>
<p>Visual GC 是常常使用的一个功能，可以明显的看到年轻代、老年代的内存变化，以及gc频率、gc的时间等。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172627308.webp" alt="img"></p>
<p>以上的功能其实jconsole几乎也有，VisualVM更全面更直观一些，另外VisualVM非常多的其它功能，可以分析dump的内存快照，</p>
<p>dump出来的线程快照并且进行分析等，还有其它很多的插件大家可以去探索</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605376.webp" alt="img"></p>
<h1 id="案例分析"><a href="#案例分析" class="headerlink" title="案例分析"></a>案例分析</h1><h2 id="准备模拟内存泄漏样例"><a href="#准备模拟内存泄漏样例" class="headerlink" title="准备模拟内存泄漏样例"></a>准备模拟内存泄漏样例</h2><p>1、定义静态变量HashMap</p>
<p>2、分段循环创建对象，并加入HashMap</p>
<p>代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">&#96;import java.util.HashMap;  </span><br><span class="line">import java.util.Map;  </span><br><span class="line">public class CyclicDependencies &#123;  </span><br><span class="line">    &#x2F;&#x2F;声明缓存对象  </span><br><span class="line">    private static final Map map &#x3D; new HashMap();  </span><br><span class="line">    public static void main(String args[])&#123;  </span><br><span class="line">        try &#123;  </span><br><span class="line">            Thread.sleep(10000);&#x2F;&#x2F;给打开visualvm时间  </span><br><span class="line">        &#125; catch (InterruptedException e) &#123;  </span><br><span class="line">            e.printStackTrace();  </span><br><span class="line">        &#125;  </span><br><span class="line">        &#x2F;&#x2F;循环添加对象到缓存  </span><br><span class="line">        for(int i&#x3D;0; i&lt;1000000;i++)&#123;  </span><br><span class="line">            TestMemory t &#x3D; new TestMemory();  </span><br><span class="line">            map.put(&quot;key&quot;+i,t);  </span><br><span class="line">        &#125;  </span><br><span class="line">        System.out.println(&quot;first&quot;);  </span><br><span class="line">        &#x2F;&#x2F;为dump出堆提供时间  </span><br><span class="line">        try &#123;  </span><br><span class="line">            Thread.sleep(10000);  </span><br><span class="line">        &#125; catch (InterruptedException e) &#123;  </span><br><span class="line">            e.printStackTrace();  </span><br><span class="line">        &#125;  </span><br><span class="line">        for(int i&#x3D;0; i&lt;1000000;i++)&#123;  </span><br><span class="line">            TestMemory t &#x3D; new TestMemory();  </span><br><span class="line">            map.put(&quot;key&quot;+i,t);  </span><br><span class="line">        &#125;  </span><br><span class="line">        System.out.println(&quot;second&quot;);  </span><br><span class="line">        try &#123;  </span><br><span class="line">            Thread.sleep(10000);  </span><br><span class="line">        &#125; catch (InterruptedException e) &#123;  </span><br><span class="line">            e.printStackTrace();  </span><br><span class="line">        &#125;  </span><br><span class="line">        for(int i&#x3D;0; i&lt;3000000;i++)&#123;  </span><br><span class="line">            TestMemory t &#x3D; new TestMemory();  </span><br><span class="line">            map.put(&quot;key&quot;+i,t);  </span><br><span class="line">        &#125;  </span><br><span class="line">        System.out.println(&quot;third&quot;);  </span><br><span class="line">        try &#123;  </span><br><span class="line">            Thread.sleep(10000);  </span><br><span class="line">        &#125; catch (InterruptedException e) &#123;  </span><br><span class="line">            e.printStackTrace();  </span><br><span class="line">        &#125;  </span><br><span class="line">        for(int i&#x3D;0; i&lt;4000000;i++)&#123;  </span><br><span class="line">            TestMemory t &#x3D; new TestMemory();  </span><br><span class="line">            map.put(&quot;key&quot;+i,t);  </span><br><span class="line">        &#125;  </span><br><span class="line">        System.out.println(&quot;forth&quot;);  </span><br><span class="line">        try &#123;  </span><br><span class="line">            Thread.sleep(Integer.MAX_VALUE);  </span><br><span class="line">        &#125; catch (InterruptedException e) &#123;  </span><br><span class="line">            e.printStackTrace();  </span><br><span class="line">        &#125;  </span><br><span class="line">        System.out.println(&quot;qqqq&quot;);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;  </span><br><span class="line">&#96;</span><br></pre></td></tr></table></figure>

<p>3、配置jvm参数如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#96;         -Xms512m  </span><br><span class="line">         -Xmx512m  </span><br><span class="line">         -XX:-UseGCOverheadLimit  </span><br><span class="line">         -XX:MaxPermSize&#x3D;50m  </span><br><span class="line">&#96;</span><br></pre></td></tr></table></figure>

<p>4、运行程序并打卡visualvm监控</p>
<h2 id="使用JVisualVM分析内存泄漏"><a href="#使用JVisualVM分析内存泄漏" class="headerlink" title="使用JVisualVM分析内存泄漏"></a>使用JVisualVM分析内存泄漏</h2><p>1、查看Visual GC标签，内容如下，这是输出first的截图</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605790.png" alt="img"></p>
<p>这是输出forth的截图：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605479.png" alt="img"></p>
<p>通过2张图对比发现：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605634.webp" alt="img"></p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605790.webp" alt="img"></p>
<p>老生代一直在gc，当程序继续运行可以发现老生代gc还在继续：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605788.webp" alt="img"></p>
<p>增加到了7次，但是老生代的内存并没有减少。说明存在无法被回收的对象，可能是内存泄漏了。</p>
<p>如何分析是那个对象泄漏了呢？打开抽样器标签：点击后如下图：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605789.webp" alt="img"></p>
<p>按照程序输出进行堆dump，当输出second时，dump一次，当输出forth时dump一次。</p>
<p>进入最后dump出来的堆标签，点击类：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605377.webp" alt="img"></p>
<p>点击右上角：“与另一个堆存储对比”。如图选择第一次导出的dump内容比较：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605139.png" alt="img"></p>
<p>比较结果如下：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605634.png" alt="img"></p>
<p>可以看出在两次间隔时间内TestMemory对象实例一直在增加并且多了，说明该对象引用的方法可能存在内存泄漏。</p>
<p>如何查看对象引用关系呢？</p>
<p>右键选择类TestMemory，选择“在实例视图中显示”，如下所示：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605789.png" alt="img"></p>
<p>左侧是创建的实例总数，右侧上部为该实例的结构，下面为引用说明，从图中可以看出在类CyclicDependencies里面被引用了，并且被HashMap引用。</p>
<p>如此可以确定泄漏的位置，进而根据实际情况进行分析解决。</p>
<h2 id="JVisualVM-远程监控-Tomcat"><a href="#JVisualVM-远程监控-Tomcat" class="headerlink" title="JVisualVM 远程监控 Tomcat"></a>JVisualVM 远程监控 Tomcat</h2><p>1、修改远程tomcat的catalina.sh配置文件，在其中增加：</p>
<ol>
<li><p>JAVA_OPTS=”$JAVA_OPTS</p>
</li>
<li><p>-Djava.rmi.server.hostname=192.168.122.128</p>
</li>
<li><p>-Dcom.sun.management.jmxremote.port=18999</p>
</li>
<li><p>-Dcom.sun.management.jmxremote.ssl=false</p>
</li>
<li><p>-Dcom.sun.management.jmxremote.authenticate=false”</p>
<p>这次配置先不走权限校验。只是打开jmx端口。</p>
<p>2、打开jvisualvm，右键远程，选择添加远程主机：</p>
</li>
</ol>
<p><img src="http://iubest.gitee.io/pic/640-1601172605786.webp" alt="img"></p>
<p>3、输入主机的名称，直接写ip，如下：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601172605391.webp" alt="img"></p>
<p>右键新建的主机，选择添加JMX连接，输入在tomcat中配置的端口即可。</p>
<p>4、双击打开。完毕！</p>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/kl28978113/article/details/53817827">https://blog.csdn.net/kl28978113/article/details/53817827</a></p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/ityouknow/p/6437037.html">https://www.cnblogs.com/ityouknow/p/6437037.html</a></p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/tips/%E6%9C%89%E4%BA%86%E8%BF%99%E6%AC%BE%E5%8F%AF%E8%A7%86%E5%8C%96%E5%B7%A5%E5%85%B7JVisualVM%20%EF%BC%8CJava%20%E5%BA%94%E7%94%A8%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/tips/" rel="tag">tips</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/tips/%E6%8E%A8%E8%8D%90%E8%BF%9922%E6%AC%BE%E9%AB%98%E9%A2%9C%E5%80%BC%E7%9A%84%E7%BB%88%E7%AB%AF%E5%B7%A5%E5%85%B7/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            推荐这22款高颜值的终端工具.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/tips/%E7%94%A8%E5%8A%A8%E5%9B%BE%E5%B1%95%E7%A4%BA10%E5%A4%A7Git%E5%91%BD%E4%BB%A4/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">用动图展示10大Git命令.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>